<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <!-- hexo-inject:begin --><!-- hexo-inject:end --><meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/stark.ico?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="Instacart购物篮分析数据来源Instacart 开源购物订单数据：https://www.instacart.com/datasets/grocery-shopping-2017Instacart是一家创业公司，提供食品的订购和送货服务。2017年该公司发布了“The Instacart Online Grocery Shopping Dataset 2017 ”，该数据集包含了来自20多">
<meta property="og:type" content="website">
<meta property="og:title" content="R语言Instacart购物篮分析">
<meta property="og:url" content="http://yoursite.com/TEMP/R语言Instacart购物篮分析.html">
<meta property="og:site_name" content="Everglow">
<meta property="og:description" content="Instacart购物篮分析数据来源Instacart 开源购物订单数据：https://www.instacart.com/datasets/grocery-shopping-2017Instacart是一家创业公司，提供食品的订购和送货服务。2017年该公司发布了“The Instacart Online Grocery Shopping Dataset 2017 ”，该数据集包含了来自20多">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-06-12T09:55:41.904Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="R语言Instacart购物篮分析">
<meta name="twitter:description" content="Instacart购物篮分析数据来源Instacart 开源购物订单数据：https://www.instacart.com/datasets/grocery-shopping-2017Instacart是一家创业公司，提供食品的订购和送货服务。2017年该公司发布了“The Instacart Online Grocery Shopping Dataset 2017 ”，该数据集包含了来自20多">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"right","display":"always","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/TEMP/R语言Instacart购物篮分析.html"/>





  <title>R语言Instacart购物篮分析 | Everglow</title><!-- hexo-inject:begin --><!-- hexo-inject:end -->
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <!-- hexo-inject:begin --><!-- hexo-inject:end --><div class="container sidebar-position-right page-post-detail">
    <div class="headband"></div>
    <a href="https://github.com/LeoWood" class="github-corner" aria-label="View source on Github"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Everglow</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">Dance in the rain.</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    
    
    
    <div class="post-block page">
      <header class="post-header">

	<h1 class="post-title" itemprop="name headline">R语言Instacart购物篮分析</h1>



</header>

      
      
      
      <div class="post-body">
        
        
          <h2 id="Instacart购物篮分析"><a href="#Instacart购物篮分析" class="headerlink" title="Instacart购物篮分析"></a>Instacart购物篮分析</h2><h3 id="数据来源"><a href="#数据来源" class="headerlink" title="数据来源"></a>数据来源</h3><p>Instacart 开源购物订单数据：<a href="https://www.instacart.com/datasets/grocery-shopping-2017" target="_blank" rel="noopener">https://www.instacart.com/datasets/grocery-shopping-2017</a><br>Instacart是一家创业公司，提供食品的订购和送货服务。2017年该公司发布了“The Instacart Online Grocery Shopping Dataset 2017 ”，该数据集包含了来自20多万个用户的300多万个购物订单。</p>
<h3 id="数据介绍"><a href="#数据介绍" class="headerlink" title="数据介绍"></a>数据介绍</h3><figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">library</span>(readr)</span><br><span class="line">orders &lt;- read_csv(<span class="string">'orders.csv'</span>)</span><br><span class="line">products &lt;- read_csv(<span class="string">'products.csv'</span>)</span><br><span class="line">order_products &lt;- read_csv(<span class="string">'order_products__train.csv'</span>)</span><br><span class="line">order_products_prior &lt;- read_csv(<span class="string">'order_products__prior.csv'</span>)</span><br><span class="line">aisles &lt;- read_csv(<span class="string">'aisles.csv'</span>)</span><br><span class="line">departments &lt;- read_csv(<span class="string">'departments.csv'</span>)</span><br></pre></td></tr></table></figure>
<figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">head(orders,<span class="number">10</span>)</span><br><span class="line">head(products,<span class="number">10</span>)</span><br><span class="line">head(order_products,<span class="number">10</span>)</span><br><span class="line">head(order_products_prior,<span class="number">10</span>)</span><br><span class="line">head(aisles,<span class="number">10</span>)</span><br><span class="line">head(departments,<span class="number">10</span>)</span><br></pre></td></tr></table></figure>
<figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">library</span>(dplyr)</span><br><span class="line">orders &lt;- mutate(orders, order_hour_of_day = as.numeric(order_hour_of_day), eval_set = as.factor(eval_set))</span><br><span class="line">products &lt;- mutate(products, product_name = as.factor(product_name))</span><br><span class="line">aisles &lt;- mutate(aisles, aisle = as.factor(aisle))</span><br><span class="line">departments &lt;- mutate(departments, department = as.factor(department))</span><br></pre></td></tr></table></figure>
<figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">library</span>(ggplot2)</span><br><span class="line"><span class="keyword">library</span>(scales)</span><br><span class="line">ggplot(orders, aes(x=order_hour_of_day)) + </span><br><span class="line">  geom_histogram(stat=<span class="string">"count"</span>) +</span><br><span class="line">  geom_bar(fill = c(rep(<span class="string">"grey25"</span>, <span class="number">10</span>), <span class="string">"gold"</span>, rep(<span class="string">"grey25"</span>, <span class="number">4</span>), <span class="string">"cyan3"</span>, rep(<span class="string">"grey25"</span>, <span class="number">8</span>))) +</span><br><span class="line">  labs(x = <span class="string">"Hour of the Day"</span>,</span><br><span class="line">       y = <span class="string">"Count"</span>,</span><br><span class="line">       title = <span class="string">"Distribution of Orders by Hour of the Day"</span>) +</span><br><span class="line">  scale_y_continuous(labels = comma)</span><br></pre></td></tr></table></figure>
<figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">ggplot(orders, aes(x=order_dow)) + </span><br><span class="line">  geom_histogram(stat=<span class="string">"count"</span>) +</span><br><span class="line">  geom_bar(fill=c(rep(<span class="string">"gold"</span>,<span class="number">2</span>),rep(<span class="string">"gray25"</span>,<span class="number">5</span>))) +</span><br><span class="line">  labs(x = <span class="string">"Day of the Week"</span>,</span><br><span class="line">       y = <span class="string">"Count"</span>,</span><br><span class="line">       title = <span class="string">"Distribution of Orders by Day of the Week"</span>) +</span><br><span class="line">  scale_y_continuous(labels = comma)</span><br></pre></td></tr></table></figure>
<figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">library</span>(gridExtra)      </span><br><span class="line"></span><br><span class="line">p0 &lt;- ggplot(filter(orders,order_dow == <span class="number">0</span>), aes(x = order_hour_of_day)) +</span><br><span class="line">  geom_bar(fill = c(rep(<span class="string">"grey25"</span>, <span class="number">14</span>), <span class="string">"gold"</span>, rep(<span class="string">"grey25"</span>, <span class="number">9</span>))) +</span><br><span class="line">  labs(y = <span class="string">"Day 0"</span>)</span><br><span class="line"></span><br><span class="line">p1 &lt;- ggplot(filter(orders,order_dow == <span class="number">1</span>), aes(x = order_hour_of_day)) +</span><br><span class="line">  geom_bar(fill = c(rep(<span class="string">"grey25"</span>, <span class="number">10</span>), <span class="string">"gold"</span>, rep(<span class="string">"grey25"</span>, <span class="number">13</span>))) +</span><br><span class="line">  labs(y = <span class="string">"Day 1"</span>)</span><br><span class="line"></span><br><span class="line">p2 &lt;- ggplot(filter(orders,order_dow == <span class="number">2</span>), aes(x = order_hour_of_day)) +</span><br><span class="line">  geom_bar(fill = c(rep(<span class="string">"grey25"</span>, <span class="number">10</span>), <span class="string">"gold"</span>, rep(<span class="string">"grey25"</span>, <span class="number">13</span>))) +</span><br><span class="line">  labs(y = <span class="string">"Day 2"</span>)</span><br><span class="line"></span><br><span class="line">p3 &lt;- ggplot(filter(orders,order_dow == <span class="number">3</span>), aes(x = order_hour_of_day)) +</span><br><span class="line">  geom_bar(fill = c(rep(<span class="string">"grey25"</span>, <span class="number">10</span>), <span class="string">"gold"</span>, rep(<span class="string">"grey25"</span>, <span class="number">13</span>))) +</span><br><span class="line">  labs(y = <span class="string">"Day 3"</span>)</span><br><span class="line"></span><br><span class="line">p4 &lt;- ggplot(filter(orders,order_dow == <span class="number">4</span>), aes(x = order_hour_of_day)) +</span><br><span class="line">  geom_bar(fill = c(rep(<span class="string">"grey25"</span>, <span class="number">10</span>), <span class="string">"gold"</span>, rep(<span class="string">"grey25"</span>, <span class="number">13</span>))) +</span><br><span class="line">  labs(y = <span class="string">"Day 4"</span>)</span><br><span class="line"></span><br><span class="line">p5 &lt;- ggplot(filter(orders,order_dow == <span class="number">5</span>), aes(x = order_hour_of_day)) +</span><br><span class="line">  geom_bar(fill = c(rep(<span class="string">"grey25"</span>, <span class="number">10</span>), <span class="string">"gold"</span>, rep(<span class="string">"grey25"</span>, <span class="number">13</span>))) +</span><br><span class="line">  labs(y = <span class="string">"Day 5"</span>)</span><br><span class="line"></span><br><span class="line">p6 &lt;- ggplot(filter(orders,order_dow == <span class="number">6</span>), aes(x = order_hour_of_day)) +</span><br><span class="line">  geom_bar(fill = c(rep(<span class="string">"grey25"</span>, <span class="number">14</span>), <span class="string">"gold"</span>, rep(<span class="string">"grey25"</span>, <span class="number">9</span>))) +</span><br><span class="line">  labs(y = <span class="string">"Day 6"</span>,</span><br><span class="line">       x = <span class="string">"Hour of the Day"</span>)</span><br><span class="line"></span><br><span class="line">grid.arrange(p0, p1, p2, p3, p4, p5, p6, ncol = <span class="number">1</span>)</span><br></pre></td></tr></table></figure>
<figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">ggplot(orders, aes(x = days_since_prior_order)) + </span><br><span class="line">  geom_histogram(stat=<span class="string">"count"</span>) +</span><br><span class="line">  geom_bar(fill=c(<span class="string">"cyan3"</span>,rep(<span class="string">"gray25"</span>,<span class="number">6</span>),<span class="string">"cyan3"</span>,rep(<span class="string">"gray25"</span>,<span class="number">6</span>),<span class="string">"cyan3"</span>,rep(<span class="string">"gray25"</span>,<span class="number">6</span>),<span class="string">"cyan3"</span>,rep(<span class="string">"gray25"</span>,<span class="number">6</span>),<span class="string">"cyan3"</span>,<span class="string">"gray25"</span>,<span class="string">"cyan3"</span>)) +</span><br><span class="line">  labs(x = <span class="string">"Days Since Prior Order"</span>,</span><br><span class="line">       y = <span class="string">"Count"</span>,</span><br><span class="line">       title = <span class="string">"Distribution of Days Since Prior Order"</span>) +</span><br><span class="line">  scale_y_continuous(labels = comma)</span><br></pre></td></tr></table></figure>
<figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">ordered_trans1rules &lt;- sort(trans1rules, by=<span class="string">"lift"</span>)</span><br><span class="line">inspect(ordered_trans1rules[<span class="number">1</span>:<span class="number">10</span>])</span><br><span class="line"></span><br><span class="line">ordered_trans1rules &lt;- sort(trans1rules, by=<span class="string">"confidence"</span>)</span><br><span class="line">inspect(ordered_trans1rules[<span class="number">1</span>:<span class="number">10</span>])</span><br><span class="line"></span><br><span class="line">ordered_trans1rules &lt;- sort(trans1rules, by=<span class="string">"support"</span>)</span><br><span class="line">inspect(ordered_trans1rules[<span class="number">1</span>:<span class="number">10</span>])</span><br></pre></td></tr></table></figure>
<figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">library</span>(arulesViz)</span><br><span class="line"><span class="keyword">library</span>(RColorBrewer)</span><br><span class="line">plot(trans1rules1,</span><br><span class="line">     control=list(jitter=<span class="number">2</span>,col=rev(brewer.pal(<span class="number">9</span>, <span class="string">"Greens"</span>)[<span class="number">4</span>:<span class="number">9</span>])),</span><br><span class="line">     shading = <span class="string">'lift'</span>)</span><br></pre></td></tr></table></figure>
<figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">trans1rules1 &lt;- apriori(trans1_use, </span><br><span class="line">                        parameter = list(support = <span class="number">0.001</span>, </span><br><span class="line">                                         confidence = <span class="number">0.3</span>, </span><br><span class="line">                                         minlen = <span class="number">2</span>))</span><br><span class="line">summary(trans1rules1)</span><br></pre></td></tr></table></figure>
<figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">ordered_trans1rules1 &lt;- sort(trans1rules1, by=<span class="string">"lift"</span>)</span><br><span class="line">inspect(ordered_trans1rules1[<span class="number">1</span>:<span class="number">10</span>])</span><br><span class="line"></span><br><span class="line">ordered_trans1rules1 &lt;- sort(trans1rules1, by=<span class="string">"confidence"</span>)</span><br><span class="line">inspect(ordered_trans1rules1[<span class="number">1</span>:<span class="number">10</span>])</span><br><span class="line"></span><br><span class="line">ordered_trans1rules1 &lt;- sort(trans1rules1, by=<span class="string">"support"</span>)</span><br><span class="line">inspect(ordered_trans1rules1[<span class="number">1</span>:<span class="number">10</span>])</span><br></pre></td></tr></table></figure>
<figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">bananarules &lt;- subset(trans1rules1, items %<span class="keyword">in</span>% c(<span class="string">"Banana"</span>))</span><br><span class="line">bananarules &lt;- sort(bananarules, by=<span class="string">"lift"</span>) </span><br><span class="line">inspect(bananarules[<span class="number">1</span>:<span class="number">10</span>])</span><br></pre></td></tr></table></figure>
<figure class="highlight r"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">transactions&lt;- vector()</span><br><span class="line">j&lt;-<span class="number">0</span></span><br><span class="line"><span class="keyword">for</span>(i <span class="keyword">in</span> seq(<span class="number">1</span>,nrow(products_sold)))&#123;</span><br><span class="line">	<span class="keyword">if</span>(products_sold[i,<span class="number">1</span>]==products_sold[i+<span class="number">1</span>,<span class="number">1</span>])&#123;</span><br><span class="line">      	transactions[j]&lt;- products_sold[i,<span class="number">5</span>]</span><br><span class="line">		j&lt;-j+<span class="number">1</span></span><br><span class="line">	&#125;<span class="keyword">else</span>&#123;</span><br><span class="line">		transactions[j]&lt;-products_sold[i,<span class="number">5</span>]</span><br><span class="line">		write_csv(transactions,<span class="string">"transactions.csv"</span>, col_names = <span class="literal">FALSE</span> , append = <span class="literal">TRUE</span>)</span><br><span class="line">		transactions&lt;- vector()</span><br><span class="line">		j&lt;-<span class="number">0</span></span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
        
      </div>
      
      
      
    </div>
    
    
    
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/hepburn.png"
                alt="Leo Wood" />
            
              <p class="site-author-name" itemprop="name">Leo Wood</p>
              <p class="site-description motion-element" itemprop="description">潜沉涵泳</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">11</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">8</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">22</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/LeoWood" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:leowood@foxmail.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-inline">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                推荐阅读
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.jianshu.com/u/68f0c30bb0f1" title="简书" target="_blank">简书</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://blog.csdn.net/alanconstantinelau" title="AlanConstantineLau" target="_blank">AlanConstantineLau</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Instacart购物篮分析"><span class="nav-number">1.</span> <span class="nav-text">Instacart购物篮分析</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#数据来源"><span class="nav-number">1.1.</span> <span class="nav-text">数据来源</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#数据介绍"><span class="nav-number">1.2.</span> <span class="nav-text">数据介绍</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>

<!--  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>-->

  <span class="author" itemprop="copyrightHolder">❤ Leo Wood</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">11.3k</span>
  
</div>

<!--
<div class="powered-by">
<i class="fa fa-user-md"></i><span id="busuanzi_container_site_uv">
  本站访客数:<span id="busuanzi_value_site_uv"></span>&nbsp;&nbsp;|&nbsp;&nbsp;
</span>
</div>
-->


    <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span id="busuanzi_container_site_pv">本站总访问量<span id="busuanzi_value_site_pv"></span>次</span>
    <span class="post-meta-divider">|</span>
    <span id="busuanzi_container_site_uv">本站访客数<span id="busuanzi_value_site_uv"></span>人</span>


<!--下面三段，分别是Powered by Hexo | 主题


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>


-->



        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  

  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script><!-- hexo-inject:begin --><!-- hexo-inject:end -->



  


  




	





  





  












  





  

  

  

  
  

  
  


  

  


  
</body>
</html>
<script type="text/javascript" src="/js/src/love.js"></script>
